﻿using Company.Sqlite.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Company.Sqlite.Repositories
{
    public class CompanyRepository : RepositoryBase, ICompanyRepository
    {
        public int Delete(Models.Company entity)
        {
            db.Entry(entity).State = System.Data.Entity.EntityState.Deleted;
            return db.SaveChanges();
        }

        public Models.Company Get(int id)
        {
            return db.Companys.Find(id);
        }

        public List<Models.Company> GetAll()
        {
            return db.Companys.ToList();
        }

        public List<Models.Company> GetAll(string keyword)
        {
            return db.Companys.ToList().Where(t => t.Name.Contains(keyword)).ToList();
        }

        public int Insert(Models.Company entity)
        {
            db.Companys.Add(entity);
            return db.SaveChanges();
        }

        public Models.Company Select(string keyword)
        {
            return db.Companys.ToList().Find(t => t.Name== keyword);

        }

        public int Update(Models.Company entity)
        {
            db.Entry(entity).State = System.Data.Entity.EntityState.Modified; 
            return db.SaveChanges();
        }
    }
}
